package com.kingyea.mobilepolice.apimanage.log.controller;

import com.kingyea.mobilepolice.apimanage.log.OperateType;
import com.kingyea.mobilepolice.apimanage.log.OperationLogAnnotation;
import com.kingyea.mobilepolice.apimanage.log.bean.OperationLog;
import com.kingyea.mobilepolice.apimanage.log.service.OperationLogService;
import com.kingyea.mobilepolice.apimanage.provider.vo.ProviderVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description OperationLog 控制层
 * @date Created in 2018-02-27 16:20:46
 */
@RequestMapping(value = "/operationLog")
@RestController
public class OperationLogController {

    private static final Logger LOGGER = LoggerFactory.getLogger(OperationLogController.class);

    @Autowired
    private OperationLogService operationLogService;


    /**
     * 条件查询
     *
     * @param map
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "根据搜索条件搜索服务方列表", notes = "", response = ProviderVO.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNum", value = "第几页", required = true, dataType = "int")
            , @ApiImplicitParam(name = "pageSize", value = "每页数据数量大小", required = true, dataType = "int")
            , @ApiImplicitParam(name = "keyword", value = " 关键字keyword，订单号和代理商名字 ", required = false, dataType = "Integer")
            , @ApiImplicitParam(name = "searchType", value = " 搜索类型（serialNo.请求者标识 requester.请求方名称 requestNetwork.请求方所属的网络类型 organizationId.管理单位机构代码 organization.管理单位名称 requestMac.请求者的mac地址 userId.注册用户） ", required = true, dataType = "String")
            , @ApiImplicitParam(name = "operateType", value = " 操作类型：1查、2增、3改、4删  ", required = true, dataType = "String")
    })
    @OperationLogAnnotation(operateName = "带条件查询操作日志列表", operateType = OperateType.SELECT, module = "log")
    @RequestMapping(value = "/searchByCondition", method = RequestMethod.POST)
    public Object searchByCondition(@RequestBody Map<String, Object> map) throws Exception {
        Object data = operationLogService.searchByCondition(map);
        return data;
    }


    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @OperationLogAnnotation(operateName = "查询所有操作日志列表", operateType = OperateType.SELECT, module = "log")
    @RequestMapping(method = RequestMethod.GET)
    public Object list() throws Exception {
        return operationLogService.list(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @OperationLogAnnotation(operateName = "通过ID查找操作日志", operateType = OperateType.SELECT, module = "log")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Object detail(@PathVariable Long id) throws Exception {
        return operationLogService.getById(id);
    }

    /**
     * 创建
     *
     * @param operationLog
     * @return
     */
    @OperationLogAnnotation(operateName = "创建操作日志", operateType = OperateType.INSERT, module = "log")
    @RequestMapping(method = RequestMethod.POST)
    public Object create(@RequestBody OperationLog operationLog) throws Exception {
        return operationLogService.save(operationLog);
    }

    /**
     * 异步创建 测试用
     *
     * @param operationLog
     * @return
     */
    @OperationLogAnnotation(operateName = "异步创建操作日志", operateType = OperateType.INSERT, module = "log")
    @RequestMapping(value = "asyncSave", method = RequestMethod.POST)
    public Object asyncSave(@RequestBody OperationLog operationLog) throws Exception {
        return operationLogService.asyncSave(operationLog);
    }

    /**
     * 更新
     *
     * @param operationLog
     * @return
     */
    @OperationLogAnnotation(operateName = "更新操作日志", operateType = OperateType.UPDATE, module = "log")
    @RequestMapping(method = RequestMethod.PUT)
    public Object update(@RequestBody OperationLog operationLog) throws Exception {
        return operationLogService.update(operationLog);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @OperationLogAnnotation(operateName = "删除操作日志", operateType = OperateType.DELETE, module = "log")
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Object delete(@PathVariable Long id) throws Exception {
        return operationLogService.deleteById(id);
    }

}
